package com.ys.web.pay.mapper;

import com.ys.base.BaseDao;
import com.ys.web.pay.model.BusiRedDealRecordCash;
import com.ys.web.pay.model.RedRecordCash;
import com.ys.web.user.login.LoginInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface RedPacketMapper extends BaseDao {

    List<Map<String,Object>> getRedListByUser(Map<String, Object> map);

    void saveBusiRedRecord(RedRecordCash RedRecordCash);

    int updateRedRecordCash(RedRecordCash redRecord);

    void saveBusiRedDealRecordCash(BusiRedDealRecordCash busiRedDealRecordCash);

    @Select("select a.raw_add_time as redTime, a.user_id as id,a.amount," +
            "b.nickName,b.avatarUrl from busi_red_deal_record_cash a " +
            "LEFT JOIN user_wx b on a.user_id=b.id where a.red_id=#{redId}")
    List<LoginInfo> userRedRecordList(String redId);

    @Select("select * from busi_red_record_cash where red_status = #{EQ_status} and raw_add_time < #{addTime}")
    List<RedRecordCash> getRedRecordCashList(Map<String, Object> map);

    @Select("select ifnull(sum(amount),0) from busi_red_deal_record_cash where red_id=#{redId}")
    long getSumAmount(Long redId);

    @Select("select * from busi_red_record_cash where id=#{id}")
    RedRecordCash getRedRecordCashById(Long id);

    List<RedRecordCash> getUnGrad(Map<String, Object> map);

    List<Long> getGradByRedIds(@Param("list") List<Long> list, @Param("uid")long uid);

    @Select("SELECT COUNT(0) FROM `busi_red_record_cash` WHERE red_status = 1 AND user_id = #{uid} AND payChannel=2")
    int redNum(@Param("uid")long uid);
}
